home *** CD-ROM | disk | FTP | other *** search
/ Freelog 46 / Freelog046.iso / Alu / Celestia / Win32LoresTex / celestia-lores-win32-1.3.0.exe / {app} / shaders / specular_arb.vp < prev    next >
Text File  |  2003-02-17  |  2KB  |  81 lines

  1. !!ARBvp1.0
  2.  
  3. # Compute specular and diffuse light from a single source, as well
  4. # as a haze effect.
  5.  
  6. ATTRIB iPos          = vertex.position;
  7. ATTRIB iNormal       = vertex.normal;
  8. ATTRIB iTex0         = vertex.texcoord[0];
  9. ATTRIB iTex1         = vertex.texcoord[1];
  10. PARAM  mvp[4]        = { state.matrix.mvp };
  11. PARAM  lightDir      = program.env[0];
  12. PARAM  eyePos        = program.env[1];
  13. PARAM  diffuse       = program.env[2];
  14. PARAM  specExp       = program.env[4];
  15. PARAM  specular      = program.env[3];
  16. PARAM  ambient       = program.env[5];
  17. PARAM  zero          = 0;
  18. PARAM  one           = 1;
  19. OUTPUT oPos          = result.position;
  20. OUTPUT oColor        = result.color;
  21. OUTPUT oSpecColor    = result.color.secondary;
  22. OUTPUT oTex0         = result.texcoord[0];
  23. OUTPUT oTex1         = result.texcoord[1];
  24. OUTPUT oFog          = result.fogcoord;
  25.  
  26. TEMP   diffuseFactor;
  27. TEMP   eyeVec;
  28. TEMP   halfAngle;
  29. TEMP   dotProds;
  30.  
  31. # Transform the vertex by the modelview matrix
  32. DP4   oPos.x, mvp[0], iPos;
  33. DP4   oPos.y, mvp[1], iPos;
  34. DP4   oPos.z, mvp[2], iPos;
  35. DP4   oPos.w, mvp[3], iPos;
  36.  
  37. # Compute the diffuse light component
  38. DP3   diffuseFactor, iNormal, lightDir;
  39. # Clamp the diffuse component to zero
  40. MAX   diffuseFactor, diffuseFactor, zero;
  41.  
  42. # Get the vector from the eye to the vertex
  43. SUB   eyeVec, eyePos, iPos;
  44.  
  45. # Normalize it
  46. DP3   eyeVec.w, eyeVec, eyeVec;
  47. RSQ   eyeVec.w, eyeVec.w;
  48. MUL   eyeVec, eyeVec, eyeVec.w;
  49.  
  50. # Haze
  51. DP3   diffuseFactor.y, iNormal, eyeVec;
  52. SUB   diffuseFactor.y, one, diffuseFactor.y;
  53. MUL   oFog.x, diffuseFactor.x, diffuseFactor.y;
  54.  
  55. # Compute the half angle vector for specular lighting
  56. ADD   halfAngle, eyeVec, lightDir;
  57. DP3   halfAngle.w, halfAngle, halfAngle;
  58. RSQ   halfAngle.w, halfAngle.w;
  59. MUL   halfAngle, halfAngle, halfAngle.w;
  60.  
  61. # Set up the specular dot products vectors:
  62. #    dotProds = { diffuse factor, spec factor, 0, spec exponent }
  63. MOV   dotProds.x, diffuseFactor.x;
  64. DP3   dotProds.y, halfAngle, iNormal;
  65. MAX   dotProds.y, dotProds.y, zero;
  66. MOV   dotProds.w, specExp.w;
  67.  
  68. # Output the texture
  69. MOV   oTex0, iTex0;
  70. MOV   oTex1, iTex1;
  71.  
  72. # Output the primary color
  73. MAD   oColor, diffuse, diffuseFactor.x, ambient;
  74.  
  75. # Compute and output the secondary color
  76. LIT   dotProds, dotProds;
  77. MUL   oSpecColor, specular, dotProds.z;
  78.  
  79. END
  80.  
  81.